class Solution {
    public boolean isHappy(int n) {
        HashSet<Integer> set=new HashSet<>();
        while(n!=1&&!set.contains(n))
        {
            set.add(n);
            n=getsum(n);
        }
        return n==1;
    }
    public int getsum(int n)
    {
        int sum=0;
        int shu;
        while(n!=0)
        {
            shu=n%10;
            n/=10;
            sum+=shu*shu;
        }
        return sum;
    }
}
